package cn.galudisu.reactivemanifesto

import akka.actor.{ActorRef, ActorSystem, Props}
import akka.http.scaladsl._
import akka.http.scaladsl.model.Uri
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import akka.stream.ActorMaterializer
import cn.galudisu.reactivemanifesto.HttpWithCircuitBreaker.system
import cn.galudisu.reactivemanifesto.event.{CircuitBreakerBus, Panel}
import cn.galudisu.reactivemanifesto.interceptor.InterceptorDirectives.intercept

import scala.language.implicitConversions

object HttpWithCircuitBreaker extends App {
  implicit val system       = ActorSystem()
  implicit val materializer = ActorMaterializer()
  implicit val ec           = system.dispatcher

  val interupt = Interrupt()

  val PORT1 = Booklet("某服务依赖1",Set("http://localhost:9000/api/player"))

  val PORT2 = Booklet("某服务依赖2",Set("http://localhost:9000/api/game"))


  val routes: Route = {
    intercept(PORT1 -> interupt) {
      logRequestResult("server") {
        (get & path("register")) {
          complete("hello world")
        }
      }
    }~
    intercept(PORT2 -> interupt) {
      logRequestResult("server") {
        (get & path("player")) {
          complete("hello world")
        }
      }
    }
  }

  Http().bindAndHandle(routes, "0.0.0.0", 9001)

}































